package com.piao.controller;


import com.piao.controller.vo.BlogIndexVO;
import com.piao.controller.vo.CategoryIndexVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author 11092
 */
@Api(tags = "博客首页信息接口")
@Controller
public class IndexController {

    @GetMapping({"", "/", "/index"})
    public String index(HttpServletRequest request) {
    //1.文章信息
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<BlogIndexVO> indexVOArrayList = new ArrayList<>();

        BlogIndexVO blogIndexVO = new BlogIndexVO();
        blogIndexVO.setTitle("MyBatis笔记(二)——配置(环境配置，别名优化，mapper映射器，属性 properties)，生命周期和作用域");
        blogIndexVO.setDate(df.format(date));
        blogIndexVO.setTags(new String[]{"MyBatis", "MySQL", "SQL"});

        BlogIndexVO blogIndexVO2 = new BlogIndexVO();
        blogIndexVO2.setTitle("MySQL学习笔记(5)——JOIN联表查询，自连接查询，分页和排序，子查询与嵌套查询");
        blogIndexVO2.setDate(df.format(date));
        blogIndexVO2.setTags(new String[]{"MySQL", "SQL"});

        BlogIndexVO blogIndexVO3 = new BlogIndexVO();
        blogIndexVO3.setTitle("SpringBoot任务——JSoup+定时任务 定时爬取微博热搜至数据库");
        blogIndexVO3.setDate(df.format(date));
        blogIndexVO3.setTags(new String[]{"SpringBoot", "JSoup", "定时任务", "爬虫"});

        BlogIndexVO blogIndexVO4 = new BlogIndexVO();
        blogIndexVO4.setTitle("Docker容器——Redis的安装与设置密码运行");
        blogIndexVO4.setDate(df.format(date));
        blogIndexVO4.setTags(new String[]{"Docker", "Redis"});

        indexVOArrayList.add(blogIndexVO);
        indexVOArrayList.add(blogIndexVO2);
        indexVOArrayList.add(blogIndexVO3);
        indexVOArrayList.add(blogIndexVO4);

        System.out.println(indexVOArrayList);
        request.setAttribute("blogs", indexVOArrayList);

    //2.分类信息
        List<CategoryIndexVO> categoryIndexVOList = new ArrayList<>();
        CategoryIndexVO categoryIndexVO =new CategoryIndexVO();
        categoryIndexVO.setName("Java");
        categoryIndexVO.setCount(26);
        categoryIndexVO.setIcon("#icon-java");

        CategoryIndexVO categoryIndexVO2 =new CategoryIndexVO();
        categoryIndexVO2.setName("数据库");
        categoryIndexVO2.setCount(10);
        categoryIndexVO2.setIcon("#icon-database");

        CategoryIndexVO categoryIndexVO3 =new CategoryIndexVO();
        categoryIndexVO3.setName("应用框架");
        categoryIndexVO3.setCount(28);
        categoryIndexVO3.setIcon("#icon-spring");

        CategoryIndexVO categoryIndexVO4 =new CategoryIndexVO();
        categoryIndexVO4.setName("项目开发工具");
        categoryIndexVO4.setCount(9);
        categoryIndexVO4.setIcon("#icon-linux");

        categoryIndexVOList.add(categoryIndexVO);
        categoryIndexVOList.add(categoryIndexVO2);
        categoryIndexVOList.add(categoryIndexVO3);
        categoryIndexVOList.add(categoryIndexVO4);

        System.out.println(categoryIndexVOList);
        request.setAttribute("categories", categoryIndexVOList);

        //3.标签信息

        //4.推荐文章

        //5.站点信息


        return "index";
    }

    @GetMapping("/blog")
    public String blog() {

        return "blog";
    }

    @GetMapping("/category")
    public String category() {
        return "category";
    }

    @GetMapping("/tag")
    public String tag() {
        return "tag";
    }

    @GetMapping("/date")
    public String date() {
        return "date";
    }

    @GetMapping("/link")
    public String link() {
        return "link";
    }

    @GetMapping("/about")
    public String about() {
        return "/about";
    }


}
